import json
import requests

def add_code():
    try:
        reques = requests.get(url="https://troops-jms-api.huishian.com/captcha")
        print(f"状态码: {reques.status_code}")

        if reques.status_code == 200:
            print("请求成功，返回数据:")
            print(json.dumps(reques.json(), indent=2, ensure_ascii=False))
        else:
            print(f"请求失败，状态码: {reques.status_code}")

    except requests.exceptions.ConnectionError as e:
        print("连接错误:" + str(e))
    except Exception as e:
        print("发生错误:" + str(e))

# try:
#     reques = requests.get(url="https://gzjk.ejclims.com/static/json/serv_name.json")
#     reques.encoding = "utf-8"
#     my_code = reques.status_code
#     print(my_code)
#
#     if(my_code == 200):
#         print("请求成功")
#         reques_json = json.loads(reques.text)
#         for i in range(len(reques_json)):
#             print(reques_json[i])
#     else:
#         print("请求失败")
#
# except requests.exceptions.ConnectionError as e:
#     print("Connection Error:" + e)
